package com.liushuai.phoneguardian;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

public abstract class BaseSetupActivity extends Activity {
	
	protected static final String TAG = "BaseSetupActivity";
	protected SharedPreferences sp;
	private GestureDetector myGestureDetector;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		sp = getSharedPreferences("config", MODE_PRIVATE);
		myGestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener(){
			
			@Override
			public boolean onFling(MotionEvent e1, MotionEvent e2,
					float velocityX, float velocityY) {
				
				if(Math.abs(velocityX)<100){
					Log.i(TAG, "移动太慢");
					return true;
				}
				if(Math.abs(e1.getY()-e2.getY())>100){
					Log.i(TAG, "垂直方向移动过多");
					return true;
				}
				if(e1.getX()-e2.getX()>200){
					showNext();
					return true;
				}
				if(e2.getX()-e1.getX()>200){
					showPre();
					return true;
				}
				
				
				return super.onFling(e1, e2, velocityX, velocityY);
			}
			
		});
		init();
		setup();
	}

	public abstract void init();
	public abstract void setup();
	public abstract void showNext();
	/**
	 * 显示上一个
	 */
	public abstract void showPre();
	
	
	public void next(View view){
		 showNext();
	}
	public void pre(View view){
		showPre();
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		myGestureDetector.onTouchEvent(event);
		
		return super.onTouchEvent(event);
	}
		
	
}
